//
//  NewsListController.m
//  GuShiNews
//
//  Created by huachun on 2019/8/16.
//  Copyright © 2019 Jones. All rights reserved.
//

#import "NewsListController.h"
#import "NewsModel.h"
#import "HomeNewsCell.h"
#import "NewsAction.h"
#import "JoneCunChu.h"
#import "MementoCenter.h"
#import "NSObject+MementoCenter.h"

@interface NewsListController ()

@end

@implementation NewsListController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.Data_array = [NSMutableArray new];
    
    JoneCunChu *shuju=[[JoneCunChu alloc] init];
    
    if (_Type==0) {
        self.navigationItem.title=@"收藏的";
        
        if ([[NSUserDefaults standardUserDefaults] objectForKey:@"LikeArray"]) {
            [shuju recoverFormStateWithKey:@"LikeArray"];
            self.Data_array = shuju.JoneArray;
        }
    }else if (_Type==1){
        self.navigationItem.title=@"举报的";
        
        if ([[NSUserDefaults standardUserDefaults] objectForKey:@"JubaoArray"]) {
            [shuju recoverFormStateWithKey:@"JubaoArray"];
            self.Data_array = shuju.JoneArray;
        }
    }else if (_Type==2){
        self.navigationItem.title=@"历史";
        
        if ([[NSUserDefaults standardUserDefaults] objectForKey:@"histryArray"]) {
            [shuju recoverFormStateWithKey:@"histryArray"];
            self.Data_array = shuju.JoneArray;
        }
    }
    
    [self.view addSubview:self.TableView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.Data_array.count;
}

#pragma mark - UITableView DataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HomeNewsCell *cell = [HomeNewsCell cellForTableView:tableView cellForRowAtIndexPath:indexPath];
    cell.Model = [self.Data_array objectAtIndex:indexPath.row];
    return cell;
}

#pragma mark - UITableView Delegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NewsModel *model = [self.Data_array objectAtIndex:indexPath.row];
    return model.news_height;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NewsModel *model = [self.Data_array objectAtIndex:indexPath.row];
    [NewsAction Actiontodone:JonesGOTO_NewsInfo view:self dictionary:@{@"model":model}];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
